package com.zhentao.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhentao.common.Result;
import com.zhentao.domain.Area;
import com.zhentao.domain.SysSite;
import com.zhentao.domain.vo.SiteSeataData;
import com.zhentao.service.AreaService;
import com.zhentao.service.CityService;
import com.zhentao.service.SysSiteService;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: AreaController
 * @Desrciption: Mr.chengfenzhan
 * @Author: 知安_程烽展
 * @Date: 2024/9/19 10:30
 */
@RestController
@RequestMapping("/area")
public class AreaController {
    @Autowired
    private AreaService areaService;
    @Autowired
    private SysSiteService sysSiteService;
    @Autowired
    private StringRedisTemplate redis;
    @RequestMapping("/list")
    public Result getList(){
        String areaData = redis.opsForValue().get("areaData");
        List<SiteSeataData> siteSeataData = JSON.parseArray(areaData, SiteSeataData.class);
        return Result.build(siteSeataData, 200, "操作成功");
    }

//    @PostConstruct
//    public void init(){
//        List<SiteSeataData> list=new ArrayList<SiteSeataData>();
//        for (Area area : areaService.list()) {
//            SiteSeataData siteSeataData = new SiteSeataData();
//            siteSeataData.setName(area.getName());
//            List<SysSite> list1 = sysSiteService.list(Wrappers.<SysSite>lambdaQuery().eq(SysSite::getCityId, area.getId()));
//            siteSeataData.setValue((long) list1.size());
//            list.add(siteSeataData);
//        }
//        redis.opsForValue().set("areaData", JSON.toJSONString(list));
//    }
}
